﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace ConsoleApp
{
    public class demo_read_xml_from_sql
    {
        private readonly string STRDBCONNECTION = @"Data Source=.; Initial Catalog=bb; Integrated Security=True;";

        /// <summary>
        ///   <bbtest>
        ///      <bb id="1" name="ww" age="12" />
        ///      <bb id="2" name="ww" age="11" />
        ///      <bb id="3" name="ww" age="13" />
        ///      <bb id="4" name="wwb" age="12" />
        ///      <bb id="5" name="wwb" age="11" />
        ///      <bb id="6" name="wwb" age="13" />
        ///    </bbtest>
        /// </summary>
        private readonly string FORXMLRAW = @"select * from bbtest for xml raw('bb'),Root('bbtest');";

        public void demo()
        {
            using (SqlConnection conn = new SqlConnection(STRDBCONNECTION))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(FORXMLRAW, conn);
                SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                string value = string.Empty;
                while (dr.Read())
                {
                    value = dr.GetString(0);
                }
            }
        }

    }
}
